package com.smallkingson.lib_net;

import android.content.Context;

import com.smallkingson.ylib.net.http.YHttps;
import com.smallkingson.ylib.net.http.bean.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

/**
 * Created by Administrator on 2016/6/12.
 */
public class Net {
    public static void initYHttps(Context context) {
        YHttps.init(context, new YHttps.YHttpHandler() {
            @Override
            public void get(Request request, final YHttps.HttpCallback listener) {

//                OkHttpClientManager.getAsyn(request.getUrl(), null, null, new OkHttpClientManager.ResultCallback() {
//                    @Override
//                    public void onError(com.squareup.okhttp.Request request, Exception e) {
//                        listener.onError(e);
//                    }
//
//                    @Override
//                    public void onResponse(String response) {
//                        listener.onSuccess(response);
//                    }
//                });
                OkHttpUtils.get().url(request.getUrl()).build().execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int i) {
                        listener.onError(e);
                    }

                    @Override
                    public void onResponse(String s, int i) {
                        listener.onSuccess(s);
                    }
                });
            }

            @Override
            public void post(Request request, final YHttps.HttpCallback listener) {
                OkHttpUtils.postString().url(request.getUrl()).content(request.getPostString()).build().execute(new
                                                                                                                        StringCallback() {
                                                                                                                            @Override
                                                                                                                            public void onError(Call call, Exception e, int i) {
                                                                                                                                listener.onError(e);
                                                                                                                            }

                                                                                                                            @Override
                                                                                                                            public void onResponse(String s, int i) {
                                                                                                                                listener.onSuccess(s);
                                                                                                                            }
                                                                                                                        });
            }
        });
    }
}
